package com.moyu.shopapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moyu.shopapp.entity.OrderItem;
import com.moyu.shopapp.entity.vo.CartGoodsVO;
import com.moyu.shopapp.service.OrderItemService;
import com.moyu.shopapp.mapper.OrderItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
* @author ZJF
* @description 针对表【order_item】的数据库操作Service实现
* @createDate 2023-12-01 16:38:29
*/
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements OrderItemService{

    @Autowired
    private OrderItemMapper orderItemMapper;

    /**
     * 添加订单项
     * @param cartGoodsVOList 购物车列表
     * @param orderId 订单id
     * @return
     */
    @Override
    public String addOrderItem(List<CartGoodsVO> cartGoodsVOList,int orderId) {
        //通过遍历把购物车列表的货物添加到订单项表
        cartGoodsVOList.forEach(item->{
            OrderItem orderItem = new OrderItem();
            orderItem.setOrderId(orderId);
            orderItem.setGoodsId(item.getGoodsId());
            orderItem.setQuantity(item.getQuantity());
            orderItem.setPrice(item.getPrice());
            orderItemMapper.insert(orderItem);
        });

        return "添加成功";
    }
}




